package com.ruoyi.safe.controller.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.ListConstruction;
import com.ruoyi.safe.service.IListConstructionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工清单Controller
 * 
 * @author buxi
 * @date 2023-11-04
 */
@RestController
@RequestMapping("/list/construction")
public class ListConstructionController extends BaseController
{
    @Autowired
    private IListConstructionService listConstructionService;

    /**
     * 查询施工清单列表
     */
    @PreAuthorize("@ss.hasPermi('list:construction:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListConstruction listConstruction)
    {
        startPage();
        List<ListConstruction> list = listConstructionService.selectListConstructionList(listConstruction);
        return getDataTable(list);
    }

    /**
     * 导出施工清单列表
     */
    @PreAuthorize("@ss.hasPermi('list:construction:export')")
    @Log(title = "施工清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ListConstruction listConstruction)
    {
        List<ListConstruction> list = listConstructionService.selectListConstructionList(listConstruction);
        ExcelUtil<ListConstruction> util = new ExcelUtil<ListConstruction>(ListConstruction.class);
        util.exportExcel(response, list, "施工清单数据");
    }

    /**
     * 获取施工清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('list:construction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(listConstructionService.selectListConstructionById(id));
    }

    /**
     * 新增施工清单
     */
    @PreAuthorize("@ss.hasPermi('list:construction:add')")
    @Log(title = "施工清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ListConstruction listConstruction)
    {
        return toAjax(listConstructionService.insertListConstruction(listConstruction));
    }

    /**
     * 修改施工清单
     */
    @PreAuthorize("@ss.hasPermi('list:construction:edit')")
    @Log(title = "施工清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ListConstruction listConstruction)
    {
        return toAjax(listConstructionService.updateListConstruction(listConstruction));
    }

    /**
     * 删除施工清单
     */
    @PreAuthorize("@ss.hasPermi('list:construction:remove')")
    @Log(title = "施工清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(listConstructionService.deleteListConstructionByIds(ids));
    }
}
